package top.ahwyy.controller.Action;

import java.io.UnsupportedEncodingException;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.struts2.interceptor.ServletRequestAware;
import org.apache.struts2.interceptor.ServletResponseAware;

import top.ahwyy.controller.impl.cardImpl;
import top.ahwyy.controller.inter.card;
import top.ahwyy.utils.filterSpecialChar;

public class sendCardContentAction implements ServletRequestAware, ServletResponseAware {

	public HttpServletRequest request;
	public HttpServletResponse response;
	public String tt;
	public String forumTypeName;
	public String content;
	
	
	public String execute(){

		System.out.println(tt+forumTypeName+content);
		
		response.setContentType("text/html;charset=utf-8");
		
		try {
			request.setCharacterEncoding("utf-8");
		} catch (UnsupportedEncodingException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		HttpSession session = request.getSession();
		String un = session.getAttribute("un").toString();
		
		if(session.getAttribute("un") == null || session.getAttribute("un").equals(""))
			return "false";
		if(tt == null|| forumTypeName == null || content == null||tt.equals("")|| forumTypeName.equals("")|| content.equals(""))
			return "false";
		
		card ci = new cardImpl();
		
		boolean flag = false;
		flag = ci.saveCardMessage(filterSpecialChar.filterSpecialChar2(tt),filterSpecialChar.filterSpecialChar2(content) , forumTypeName, un);
		
		//System.out.print(content +"\n"+tt+"\n"+forumTypeName);
		if(flag){
			return "success";
		}
		
		return "false";
	}
	
	@Override
	public void setServletResponse(HttpServletResponse arg0) {
		// TODO Auto-generated method stub
		this.response = arg0;

	}

	@Override
	public void setServletRequest(HttpServletRequest arg0) {
		// TODO Auto-generated method stub
		this.request = arg0;

	}

}
